﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>智慧阅读平台接口测试</title>
    <script type="text/javascript" src="js/jquery-3.5.1.js"></script>

    <script type="text/javascript" src="common.js"></script>
    <script type="text/javascript">
        //var webapi = 'http://api.zjzdy.net';
        var webapi = 'http://localhost:35146'
        var demoapi = webapi;
        //var demoapi = 'http://localhost:35146'
        var tiket = 'pUrJ0igtfI/6++FvuFKMgdU42T5Ij37SkYx7umJTziUq+9fTzHgiMbAhqGTioIDD';
        var unitList = [{ UnitID: 'cb6e2f5163ec4f70a40d3aee47b7af89' }];
        var code = '101994';    //验证库
        code = '524875';        //开发库
        var gradeList = [];
        var studentModel = {};
        function GetTiket() {
            var url = webapi + '/api/BaseData/GetTicket';
            var postData = {
                "AppID": "qxh_zhydxt",
                "AppKey": "gDs/YPZm5vARSZWnQs0TZQ=="
            };
            $.ajax({
                url: url,
                type: 'get',
                dataType: 'json',
                data: postData,
                success: function (data) {
                    if (data.error == 0) {
                        tiket = data.ticket
                        alert('获取Tiket成功');
                    } else {
                        alert(data.message);
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            });
        };

        function GetCode() {
            //获取借书码
            code = $('#txtCode').val();
            alert('获取成功！');
        }

        function SearchUnitList() {
            var url = webapi + '/api/BaseData/SearchUnitList';
            var postData = {
                Ticket: tiket
            };
            $.ajax({
                url: url,
                type: 'Post',
                dataType: 'json',
                data: postData,
                success: function (data) {
                    if (data.error == 0) {
                        unitList = data.UnitList;
                        alert("获取授权学校成功, JSON：" + JSON.stringify(data));
                    } else {
                        alert(data.message);
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            });
        }

        function SearchUnitStuList() {
            if (unitList.length == 0) {
                return alert('请选获取单位信息');
            }
            var postData = {
                Ticket: tiket,
                UnitID: unitList[0].UnitID || ''
            };

            var url = demoapi + '/api/TMSStuRead/SearchUnitStuList';
            $.ajax({
                url: url,
                type: 'GET',
                dataType: 'json',
                data: postData,
                success: function (data) {
                    if (data.error == 0) {
                        gradeList = data.data;
                        alert("获取授权学校学生信息成功, JSON：" + JSON.stringify(data.data));
                    } else {
                        alert(data.message);
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            });
        }

        //保存阅读数据
        function SaveStuReadRecord() {
            var url = demoapi + '/api/TMSStuRead/SaveStuReadRecord';
            //var postData = {
            //    Ticket: tiket,
            //    UnitID: unitList[0].UnitID,
            //    StudentBaseID: '6c7ff7d5b3914d81915a4cbd636314d3',
            //    StudentName: '陈勋',
            //    LibraryCode: '100005',
            //    BookID: 'xxxxxx01',
            //    BookName: '茶花女',
            //    Author: '【法】亚历山大·小仲马',
            //    BookSynopsis: '《茶花女》是法国作家亚历山大·小仲马创作的长篇小说，也是其代表作。故事讲述了一个青年人与巴黎上流社会一位交际花曲折凄婉的爱情故事。 '
            //        + '作品通过一个妓女的爱情悲剧，揭露了法国七月王朝上流社会的糜烂生活。对贵族资产阶级的虚伪道德提出了血泪控诉。在法国文学史上，这是第一次把妓女作为主角的作品。',
            //    WordNumTotal: '179000',
            //    WordNumEffective: '17850',
            //    WordNumRead: '100',
            //    WordNumCurRead: '1000',
            //    BorrowDate: '2021-07-13 15:30:29',
            //    Remark: ''
            //};
            var postData = {
                Ticket: tiket,
                //UnitID: unitList[0].UnitID,
                StudentBaseID: studentModel.studentId,
                StudentName: studentModel.studentName,
                LibraryCode: code,
                BookID: 'xxxxxx01',
                BookName: '茶花女',
                Author: '【法】亚历山大·小仲马',
                BookSynopsis: '《茶花女》是法国作家亚历山大·小仲马创作的长篇小说，也是其代表作。故事讲述了一个青年人与巴黎上流社会一位交际花曲折凄婉的爱情故事。 '
                    + '作品通过一个妓女的爱情悲剧，揭露了法国七月王朝上流社会的糜烂生活。对贵族资产阶级的虚伪道德提出了血泪控诉。在法国文学史上，这是第一次把妓女作为主角的作品。',
                WordNumTotal: '179000',
                WordNumEffective: '17850',
                WordNumRead: '100',
                WordNumCurRead: '1000',
                BorrowDate: '2021-07-13 15:30:29',
                Remark: ''
            };
            $.ajax({
                url: url,
                type: 'POST',
                dataType: 'json',
                data: postData,
                success: function (data) {
                    if (data.error == 0) {
                        gradeList = data.data;
                        alert("接收学生阅读记录, JSON：" + JSON.stringify(data.message));
                    } else {
                        alert(data.message);
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            });
        }

        //保存阅读测试数据
        function SaveStuReadTestRecord() {
            var url = demoapi + '/api/TMSStuRead/SaveStuReadTestRecord';
            //var postData = {
            //    Ticket: tiket,
            //    UnitID: unitList[0].UnitID,
            //    StudentBaseID: '6c7ff7d5b3914d81915a4cbd636314d3',
            //    StudentName: '陈勋',
            //    LibraryCode: '100005',
            //    BookID: 'xxxxxx01',
            //    BookName: '茶花女',
            //    TestDate: '2021-07-13 15:30:29',
            //    NumTestQuestions: '54',
            //    NumCorrectAnswers: '53',
            //    Remark: ''
            //};

            var postData = {
                Ticket: tiket,
                //UnitID: unitList[0].UnitID,
                StudentBaseID: studentModel.studentId,
                StudentName: studentModel.studentName,
                LibraryCode: code,
                BookID: 'xxxxxx01',
                BookName: '茶花女',
                TestDate: '2021-07-13 15:30:29',
                NumTestQuestions: '54',
                NumCorrectAnswers: '53',
                Remark: ''
            };
            $.ajax({
                url: url,
                type: 'POST',
                dataType: 'json',
                data: postData,
                success: function (data) {
                    if (data.error == 0) {
                        gradeList = data.data;
                        alert("接收学生阅读测试记录, JSON：" + JSON.stringify(data.message));
                    } else {
                        alert(data.message);
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            });
        }


        //根据借书码获取学生信息
        function GetReadStudentByCode() {
            var url = webapi + '/api/TMSStuRead/GetReadStudentByCode';
            var postData = {
                ticket: tiket,
                libraryCode: code
            };
            $.ajax({
                url: url,
                type: 'GET',
                dataType: 'json',
                data: postData,
                success: function (data) {
                    if (data.success) {
                        alert("根据借书码获取学生信息, JSON：" + JSON.stringify(data));
                        studentModel = data.data;
                    } else {
                        alert(data.message);
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            });
        }

        //保存阅读数据
        function SaveStuReadRecordV2() {
            var url = demoapi + '/api/TMSStuRead/SaveStuReadRecord';
            var postData = {
                ticket: tiket,
                unitId: unitList[0].UnitID,
                userId: "2ea481f55a104cddbec8e6e5866088c7",
                userType: 4,
                borrowBook: [{
                    bookTemplateId: "ef56622e54154e64b597436508d5a51b",
                    bookRfId: "120987000020000000000000",
                    bookName: "生气也没关系",
                    bookPic: "",
                    wordSize: 501
                }],
                returnBook: [{
                    bookTemplateId: "b9273f8b39de4378a9a86cee2a86ffb9",
                    bookRfId: "120987000010000000000000",
                    bookName: "一园⻘菜成了精",
                    bookPic: "https://photo.skylinewebcams.com/pht/60d9a06a89b54.jpg",
                    wordSize: 302,
                    author: '【法】亚历山大·小仲马',
                    BookSynopsis: '《茶花女》是法国作家亚历山大·小仲马创作的长篇小说，也是其代表作。故事讲述了一个青年人与巴黎上流社会一位交际花曲折凄婉的爱情故事。 '
                        + '作品通过一个妓女的爱情悲剧，揭露了法国七月王朝上流社会的糜烂生活。对贵族资产阶级的虚伪道德提出了血泪控诉。在法国文学史上，这是第一次把妓女作为主角的作品。',

                }],
                brType: 3,
                bookcaseRow: 4,
                bookcaseColumn: 8,
                bookcaseNum: "X1MEYDYD",
                operationTime: "2020-07-03 18:29:36"
                //libraryCode: '100149',
                //BookID: 'xxxxxx01',
                //BookName: '茶花女',
                //Author: '【法】亚历山大·小仲马',
                //BookSynopsis: '《茶花女》是法国作家亚历山大·小仲马创作的长篇小说，也是其代表作。故事讲述了一个青年人与巴黎上流社会一位交际花曲折凄婉的爱情故事。 '
                //    + '作品通过一个妓女的爱情悲剧，揭露了法国七月王朝上流社会的糜烂生活。对贵族资产阶级的虚伪道德提出了血泪控诉。在法国文学史上，这是第一次把妓女作为主角的作品。',
                //WordNumTotal: '179000',
                //WordNumEffective: '17850',
                //WordNumRead: '100',
                //WordNumCurRead: '1000',
                //BorrowDate: '2021-07-13 15:30:29',
                //Remark: ''
            };

            postData = {
                ticket: tiket,
                unitId: '',
                userId: studentModel.studentId,
                "libraryCode": "",
                "userType": 4,
                "brType": 3,
                "borrowBook": [{
                    "bookTemplateId": "ef56622e54154e64b597436508d5a51b",
                    "bookRfId": "120987000020000000000000",
                    "bookName": "生气也没关系",
                    "bookPic ": "",
                    "bookId": "",
                    "wordSize": 501,
                    "author": "作者",
                    "bookSynopsis": "书籍简介"
                }],
                "returnBook": [{
                    "bookTemplateId": "b9273f8b39de4378a9a86cee2a86ffb9",
                    "bookRfId": "120987000010000000000000",
                    "bookName": "一园⻘菜成了精",
                    "bookPic ": "",
                    "bookId": "",
                    "wordSize": 302,
                    "author": "",
                    "bookSynopsis": ""
                }],
                "bookcaseRow": 4,
                "bookcaseColumn": 8,
                "bookcaseNum": "X1MEYDYD",
                "operationTime": "2020-07-03 18:29:36",
                "remark": ""
            };
            $.ajax({
                url: url,
                type: 'POST',
                dataType: 'json',
                data: postData,
                success: function (data) {
                    if (data.success) {
                        alert("接收学生阅读记录, JSON：" + JSON.stringify(data));
                    } else {
                        alert(data.message);
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            });
        }

        //保存阅读测试数据
        function SaveStuReadTestRecordV2() {
            var url = demoapi + '/api/TMSStuRead/SaveStuReadTestRecord';

            var postData = {
                Ticket: tiket,
                UnitID: unitList[0].UnitID,
                StudentBaseID: '2a48b03fe6764b7db6e9ebbf3c0acdd9',
                StudentName: '张若初',
                LibraryCode: '100149',
                BookID: 'xxxxxx01',
                BookName: '茶花女',
                TestDate: '2021-07-13 15:30:29',
                NumTestQuestions: '54',
                NumCorrectAnswers: '53',
                Remark: ''
            };


            //StudentBaseID: studentModel.studentId,
            //StudentName: studentModel.studentName,
            //LibraryCode: code,
            postData = {
                ticket: tiket,
                unitId: '',
                userId: studentModel.studentId,
                "libraryCode": "",
                "userType": 4,
                "bookTemplateId": "ef56622e54154e64b597436508d5a51b",
                "bookRfId": "",
                "bookName": "生气也没关系",
                "bookId": "",
                "totalQuestionNum": 4,
                "answerRightNum": 4,
                "answerFaultNum": 0,
                "testDate": new Date().format('yyyy-MM-dd hh:mm:ss'),
                "remark": ""
            };

            $.ajax({
                url: url,
                type: 'POST',
                dataType: 'json',
                data: postData,
                success: function (data) {
                    if (data.success) {
                        alert("接收学生阅读测试记录, JSON：" + JSON.stringify(data));
                    } else {
                        alert(data.message);
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            });
        }

        $(function () {

        });
    </script>
</head>
<body>
    <div>
        <button onclick="GetTiket();">获取Tiket</button>
        <button onclick="SearchUnitList();">获取学校</button>
        <button onclick="SearchUnitStuList();">获取学生基础数据</button>
        <button onclick="SaveStuReadRecord();">保存阅读数据</button>
        <button onclick="SaveStuReadTestRecord();">保存阅读测试数据</button>
    </div>
    <br />
    <div>
        <button onclick="GetReadStudentByCode();">根据借书码获取学生信息</button>
        <button onclick="SaveStuReadRecordV2();">借阅记录回调</button>
        <button onclick="SaveStuReadTestRecordV2();">做问答回调</button>
    </div>

    <div></div>
    <div>
        <input id="txtCode" placeholder="请输入借书码" />
        <button onclick="GetCode();">获取借书码</button>
    </div>
</body>
</html>
